const logger = require('log4js').getLogger()
const ObjectID = require('mongodb').ObjectID

module.exports = (req, res) => {
    require('../util/service').handlePost(req, res, (reqObj, resolve) => {
        if (!reqObj.activityId) {
            logger.error('[' + __filename + ':' + __line + ']', 'lack activityId')
            resolve({
                result: -1,
                msg: 'lack activityId'
            })
            return
        }
        const mongoMng = require('../mng/mongoMng')
        if (!mongoMng.db) {
            logger.error('[' + __filename + ':' + __line + ']', '未连接mongo')
            resolve({
                result: -1,
                msg: '系统错误'
            })
            return
        }
        mongoMng.db.collection('activity').find({
            _id: ObjectID(reqObj.activityId)
        }).toArray((err, result) => {
            if (err) {
                logger.error('[' + __filename + ':' + __line + ']', err)
                reject('system error')
                return
            }
            if (result.length == 0) {
                resolve({
                    result: -1,
                    msg: 'no activity'
                })
                return
            }
            resolve({
                result: 1,
                activityInfo: result[0]
            })
        })
    })
}